package com.yazi.mxz.common.db.dao.impl;



import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.yazi.mxz.common.db.dao.MemberVipDao;
import com.yazi.mxz.common.entity.beans.Company;
import com.yazi.mxz.common.entity.beans.MemberVip;

import com.myframework.smhj.hibernate.dao.BasicDao;

@Repository("memberVipDao")
public class MemberVipDaoImpl extends BasicDao<MemberVip> implements MemberVipDao {


	public MemberVipDaoImpl() {
		super(MemberVip.class);
		
	}

	@Override
	public Criteria getExample(MemberVip mv, String searchWord) {
		Criteria c = super.getExample(mv, searchWord);
		
		// 关联对象条件
		if (null != mv) {
			// 企业
			Company company = mv.getCompany();
			if (null != company) {
				// 企业ID
				if (null != company.getCompanyId()) {
					c.add(Restrictions.eq("company.companyId", company.getCompanyId()));
				} else {
					// ...企业其它条件
				}
			}
			// ...其它关联对象条件
		}
		
		// 关键字条件
		if(null != searchWord && !searchWord.isEmpty()){
			c.createAlias("member", "member");
			//关键字可查用户名、邮箱、手机号
			String likeWord = "%" + searchWord + "%";
			c.add(Restrictions.or(
					Restrictions.like("member.name", likeWord),
					Restrictions.or(Restrictions.like("member.email", likeWord),
							Restrictions.like("member.mobile", likeWord))));
		}
		
		return c;
	}
}
